<?php

$username = $_POST["username"];
$password = $_POST["password"];




# 链接数据库 : 

$con = mysqli_connect("localhost" , "root" , "root" , "bk2013");

# 编写sql语句; 
# - 字符串拼接; 
$sql_select = 'SELECT * FROM `usertable` WHERE `username`= "'. $username.'" AND `password`="'.$password. '"';
# 执行sql语句; 

$res = mysqli_query( $con , $sql_select );

# 我们把查询结果转换成数组，判定数组之中的数据数量; 
# 如果数组之中的数据数量大于等于1 表示我们的账号密码比对成功; 

$select_array = mysqli_fetch_all( $res );

# API sizeof 返回数组数量的API ; 
if( sizeof($select_array) >= 1 ){
      $result = [
            "message" => "登录成功",
            "code" => 1
      ];
}else{
      $result = [
            "message" => "登录失败",
            "code" => 0
      ];
}

echo json_encode($result);

# 关闭数据库

mysqli_close( $con );
// echo '{"type":"success"}';
// }else{
//       echo '{"type":"error","msg":"'. mysqli_error($con) .'"}';